#!/bin/bash

if [ "$1" == "" ]; then
 	cat /etc/asound.conf | grep "pcm.!default" | awk -F\# '{print $2}' | sed s/\ //g
	exit
fi

function set_default {
	PLUG=$1
	MODE=$2
	cat /etc/asound.conf | grep -v "pcm.!default" > /tmp/asound.conf
	echo "pcm.!default { type plug; slave.pcm \"$PLUG\" } # $MODE" >> /tmp/asound.conf
	cp /etc/asound.conf /etc/asound.conf.bak
	mv /tmp/asound.conf /etc/asound.conf
	/opt/hifiberry/bin/reconfigure-players --restart-players
}

if [ "$1" == "EQUAL" ]; then
	set_default equal EQUAL
	exit
fi

if [ "$1" == "DEFAULT" ]; then
	set_default softvol DEFAULT
	exit
fi

if [ "$1" == "SOFTVOL" ]; then
        set_default softvol SOFTVOL
        exit
fi 
